<template>
  <div>
    <el-card>
      <!-- 搜索框 -->
      <el-form :inline="true" :model="queryVo" class="demo-form-inline">
        <el-form-item label="姓名">
          <el-input v-model="queryVo.name" placeholder="讲师姓名"></el-input>
        </el-form-item>
        <el-form-item label="头衔">
          <el-select v-model="queryVo.level" placeholder="讲师头衔">
            <el-option label="首席讲师" value="0"></el-option>
            <el-option label="高级讲师" value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="开始时间">
          <el-date-picker
            v-model="queryVo.startTime"
            type="datetime"
            placeholder="选择开始时间"
            value-format="yyyy-MM-dd HH:mm:ss">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间">
          <el-date-picker
            v-model="queryVo.endTime"
            type="datetime"
            placeholder="选择结束时间"
            value-format="yyyy-MM-dd HH:mm:ss">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
          <el-button type="primary" @click="onClean">清空</el-button>
        </el-form-item>
      </el-form>

      <el-table :data="teacher.records" stripe style="width: 100%" v-loading="loading" border>
        <el-table-column prop="id" label="序号"></el-table-column>
        <el-table-column prop="name" label="姓名"></el-table-column>
        <!--    <el-table-column prop="intro" label="简介"></el-table-column>-->
        <!--    <el-table-column prop="career" label="资历"></el-table-column>-->
        <el-table-column label="头衔">
          <template slot-scope="scope">
            {{scope.row.level===1?'高级讲师':'首席讲师'}}
          </template>
        </el-table-column>
        <!--    <el-table-column prop="avatar" label="头像"></el-table-column>-->
        <el-table-column prop="sort" label="排序"></el-table-column>
        <el-table-column prop="gmtCreate" label="创建时间"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-row>
              <el-button type="primary" icon="el-icon-edit" @click="editTeacher(scope.row.id)">修改</el-button>
              <el-button type="danger" icon="el-icon-delete" @click="deleteTeacher(scope.row.id)">删除</el-button>
            </el-row>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <div class="block">
        <el-pagination
          layout="prev, pager, next"
          :total="teacher.pages">
        </el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
  import { deleteTeacherById, queryTeacher } from '@/api/edu/teacher'

  export default {
    name: 'List',
    data: function() {
      return {
        loading: false,
        teacher: {},
        queryVo: {},
        page: 1,
        size: 10
      }
    },
    created() {
      this.int()
    },
    methods: {
      int() {
        queryTeacher(this.page, this.size, this.queryVo)
          .then(res => {
            const { success, message, data } = res
            console.log(res)
            this.teacher = { ...data }
          })
      },
      onSubmit() {
        this.int()
      },
      onClean() {
        this.queryVo = {}
        this.int()
      }
      ,
      // 删除讲师信息
      deleteTeacher(id) {
        this.$confirm('此操作将永久删除该文件，是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(_ => {
          deleteTeacherById(id)
            .then(res => {
              const { success, message, data } = res
              if (success) {
                this.$message.success(message)
                this.int()
              }
            })
        }).catch(_ => {
          this.$message.success('已取消删除')
        })
      },
      // 修改讲师信息
      editTeacher(id) {
        this.$router.push({ path: `/teacher/edit/${id}` })
      }
    },
    watch: {}
  }
</script>

<style scoped>

</style>
